//
//  LGStatusBottomView.swift
//  LGWeibo
//
//  Created by 李更 on 8/14/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit

class LGStatusBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        backgroundColor = RandomColor()
        //添加控件
        let retweetBtn = addChildButtons("timeline_icon_retweet", title: "转发")
        let commentBtn = addChildButtons("timeline_icon_comment", title: "评论")
        let unlikeBtn = addChildButtons("timeline_icon_unlike", title: "赞")
        let lin1 = addChildLine()
        let lin2 = addChildLine()
        
        
        //添加约束
        retweetBtn.snp_makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentBtn)
        }
        commentBtn.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.width.equalTo(unlikeBtn)
            
        }
        unlikeBtn.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentBtn.snp_trailing)
        }
        lin1.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetBtn.snp_trailing)
        }
        lin2.snp_makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentBtn.snp_trailing)
        }
        
        
    }
    
    
    func addChildButtons(imgName : String , title : String) -> UIButton {
        let btn = UIButton()
        //背景图片
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
          btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(btn)
        return btn
    }
    func addChildLine() -> UIImageView {
        let img = UIImageView(imageName: "timeline_card_bottom_line")
        addSubview(img)
        return img
        
    }

}
